package leetcodecompetition.D348;

import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

/**
 * @Author: Siantar
 * @Date: 2023-06-04-10:50
 * @Description: 1.0
 */
public class T6472 {
    public long matrixSumQueries(int n, int[][] queries) {
        long res = 0;
        Set<Integer>[] sets = new Set[]{new HashSet(), new HashSet()};
        for (int i = queries.length - 1; i >= 0; i--) {
            int []q=queries[i];
            int type=q[0],index=q[1],value=q[2];
            if (!sets[type].contains(index)){
                res+=(long) (n-sets[type^1].size())*value;
                sets[type].add(index);
            }
        }
        return res;
    }
}
//Arrays.stream(arr).mapToLong(a -> Arrays.stream(a).sum()).sum();

